package com.ax.center.controller;

import com.ax.center.annotation.Logging;
import com.ax.center.dto.ApiResponse;
import com.ax.center.entity.AnnouncementReceiver;
import com.ax.center.service.AnnouncementReceiverService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author zy
 * @date 2023/7/10 15:55
 */
@RestController
@RequestMapping(value = "announcementReceiverController")
@Api(tags = "用户的公告服务")
@CrossOrigin(origins = "http://localhost:5173")
public class AnnouncementReceiverController {
    @Autowired
    private AnnouncementReceiverService announcementReceiverService;

    @GetMapping("/无效的请求")
    public void test(@RequestBody AnnouncementReceiver announcementReceiver){
        return;
    }

    @ApiOperation("根据用户id和排序方式进行查询")
    @GetMapping("/queryByUserId/{userId}/{orderBy}")
    public ApiResponse queryByUserId(@PathVariable("userId")Long userId,@PathVariable("orderBy")String orderBy){
        return  announcementReceiverService.queryByUserId(userId,orderBy);
    }

    @ApiOperation("修改公告阅读状态")
    @GetMapping("/updateReadStatus/{userId}/{anId}")
    public ApiResponse updateReadStatus(@PathVariable("userId")Long userId,@PathVariable("anId")Long anId){
        return announcementReceiverService.updateReadStatus(userId,anId);
    }

    @ApiOperation("删除用户的公告")
    @Logging(description = "删除用户的公告")
    @GetMapping("/deleteById/{userId}/{anId}")
    public ApiResponse deleteById(@PathVariable("userId")Long userId,@PathVariable("anId")Long anId){
        return announcementReceiverService.deleteById(userId,anId);
    }
}
